package com.huifenqi.saas.client;

import com.huifenqi.common.HfqResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @author lisheng
 * @description
 * @date 2018/11/7 10:43
 * @version:
 */
@FeignClient(name = "external-url", url = "${feign.external.url}", path = "/zhaofang", fallback = ExternalClient.ExternalClientHystrix.class)
public interface ExternalClient {

    //TODO 添加日志记录，便于排查问题
    @GetMapping(value = "/get/biz")
    HfqResponse getBiz();

    /**
     * 不添加@Component，会报以下异常
     * java.lang.IllegalStateException:
     * No fallback instance of type class com.huifenqi.saas.client.MeterClient$MeterClientHystrix found for feign client smart-service
     */
    @Component
    class ExternalClientHystrix implements ExternalClient {

        @Override
        public HfqResponse getBiz() {
            return HfqResponse.builder()
                    .code(0)
                    .msg("调用fallback")
                    .build();
        }
    }

}
